package com.betterjr.modules.risk.api.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.betterjr.common.utils.Collections3;
import com.betterjr.common.web.AbstarctRemoteApiInvoke;
import com.betterjr.common.web.AjaxRemoteApiParam;
import com.betterjr.modules.contract.IContractCorpAccountService;

@Service
public class RemoteApiSaveRegistCorpAccountInvokeService extends AbstarctRemoteApiInvoke {

    @Reference(interfaceClass = IContractCorpAccountService.class)
    private IContractCorpAccountService contractCorpAccountService;

    private String apiCode = "RAI00004";

    @Override
    public String saveOrFindInvoke(AjaxRemoteApiParam param) {

        return contractCorpAccountService.webSaveRegistCorpAccount(param.getParamMap());
    }

    @Override
    public boolean supportInvoke(String anApiCode) {
        //
        return apiCode.equals(anApiCode);
    }

    @Override
    public boolean checkParam(Map<String, Object> anParamMap) {
        boolean flag = true;

        if (flag && Collections3.isEmpty(anParamMap)) flag = false;

        if (flag && !anParamMap.containsKey("serviceCustNo")) flag = false;
        if (flag && !anParamMap.containsKey("type")) flag = false;
        if (flag && !anParamMap.containsKey("name")) flag = false;
        if (flag && !anParamMap.containsKey("identNo")) flag = false;
        if (flag && !anParamMap.containsKey("custNo")) flag = false;
        if (flag && !anParamMap.containsKey("identType")) flag = false;
        if (flag && !anParamMap.containsKey("idType")) flag = false;
        if (flag && !anParamMap.containsKey("orgCode")) flag = false;
        if (flag && !anParamMap.containsKey("mobileNo")) flag = false;
        if (flag && !anParamMap.containsKey("orgRegType")) flag = false;

        return flag;
    }

    private Map<String, Object> convertToUseMap(Map<String, Object> sourceMap) {

        Map<String, Object> map = new HashMap<>(sourceMap.size());

        map.put("serviceCustNo", findProperties(sourceMap, "serviceCustNo", Long.class));
        map.put("type", findProperties(sourceMap, "type", String.class));
        map.put("name", findProperties(sourceMap, "name", String.class));
        map.put("identNo", findProperties(sourceMap, "identNo", String.class));
        map.put("custNo", findProperties(sourceMap, "custNo", Long.class));
        map.put("identType", findProperties(sourceMap, "identType", String.class));
        map.put("idType", findProperties(sourceMap, "idType", String.class));
        map.put("orgCode", findProperties(sourceMap, "orgCode", String.class));
        map.put("mobileNo", findProperties(sourceMap, "mobileNo", String.class));
        map.put("orgRegType", findProperties(sourceMap, "orgRegType", String.class));

        return map;

    }

}
